<!DOCTYPE html>

<html lang="en">

<head>
    
    <title>docker常用 - Hexo</title>
    <meta charset="UTF-8">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
    
    

    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <meta name="description" content="docker常用的几个12345678910docker pull  [name]   拉取镜像docker search  [name]  查询docker image 查询所有镜像docker ps  查询正在运行的镜像docker ps -a  查询所有镜像 包括 停止的docker rmi -f 强制删除imagedocker rm -f 强制删除运行的镜像docker exec -it">
<meta property="og:type" content="article">
<meta property="og:title" content="docker常用">
<meta property="og:url" content="https://liuxinyan.gitee.io/2022/07/14/docker%E5%B8%B8%E7%94%A8/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="docker常用的几个12345678910docker pull  [name]   拉取镜像docker search  [name]  查询docker image 查询所有镜像docker ps  查询正在运行的镜像docker ps -a  查询所有镜像 包括 停止的docker rmi -f 强制删除imagedocker rm -f 强制删除运行的镜像docker exec -it">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2022-07-14T03:19:52.000Z">
<meta property="article:modified_time" content="2022-07-14T03:42:18.022Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
    <link rel="stylesheet" href="/lib/jquery.fancybox.min.css?v=1657770155242">
    
    <link rel="stylesheet" href="/lib/mdui_043tiny/css/mdui.css?v=1657770155242">
    <link rel="stylesheet" href="/lib/iconfont/iconfont.css?v=1657770155242">
    <link rel="stylesheet" href="/css/style.css?v=1657770155242">
     
    
<meta name="generator" content="Hexo 6.1.0"></head>

<body class="mdui-drawer-body-left">
    
    <div id="nexmoe-background">
        <div class="nexmoe-bg" style="background-image: url(https://cdn.jsdelivr.net/gh/nexmoe/nexmoe.github.io@latest/images/cover/5c3aec85a4343.jpg)"></div>
        <div class="mdui-appbar mdui-shadow-0">
            <div class="mdui-toolbar">
                <a mdui-drawer="{target: '#drawer', swipe: true}" title="menu" class="mdui-btn mdui-btn-icon mdui-ripple"><i class="mdui-icon nexmoefont icon-menu"></i></a>
                <div class="mdui-toolbar-spacer"></div>
                <!--<a href="javascript:;" class="mdui-btn mdui-btn-icon"><i class="mdui-icon material-icons">search</i></a>-->
                <a href="/" title="John Doe" class="mdui-btn mdui-btn-icon"><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.nga.178.com%2Fattachments%2Fmon_202012%2F23%2Fi2Q5-5k84ZcT3cSk4-sg.jpg.thumb.jpg&amp;refer=http%3A%2F%2Fimg.nga.178.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1650117217&amp;t=63c3561c593a6c648660832c13208805" alt="John Doe"></a>
            </div>
        </div>
    </div>
    <div id="nexmoe-header">
        <div class="nexmoe-drawer mdui-drawer" id="drawer">
    <div class="nexmoe-avatar mdui-ripple">
        <a href="/" title="John Doe">
            <img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.nga.178.com%2Fattachments%2Fmon_202012%2F23%2Fi2Q5-5k84ZcT3cSk4-sg.jpg.thumb.jpg&amp;refer=http%3A%2F%2Fimg.nga.178.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1650117217&amp;t=63c3561c593a6c648660832c13208805" alt="John Doe" alt="John Doe">
        </a>
    </div>
    <div class="nexmoe-count">
        <div><span>Articles</span>3</div>
        <div><span>Tags</span>0</div>
        <div><span>Categories</span>0</div>
    </div>
    <div class="nexmoe-list mdui-list" mdui-collapse="{accordion: true}">
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple false" href="/" title="回到首页">
            <i class="mdui-list-item-icon nexmoefont icon-home"></i>
            <div class="mdui-list-item-content">
                回到首页
            </div>
        </a>
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple false" href="/about.html" title="关于博客">
            <i class="mdui-list-item-icon nexmoefont icon-info-circle"></i>
            <div class="mdui-list-item-content">
                关于博客
            </div>
        </a>
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple false" href="/PY.html" title="我的朋友">
            <i class="mdui-list-item-icon nexmoefont icon-unorderedlist"></i>
            <div class="mdui-list-item-content">
                我的朋友
            </div>
        </a>
        
    </div>
    <aside id="nexmoe-sidebar">
    
    <div class="nexmoe-widget-wrap">
    <div class="nexmoe-widget nexmoe-search">
         
            <form id="search_form" action_e="https://cn.bing.com/search?q=site:nexmoe.com" onsubmit="return search();">
                <label><input id="search_value" name="q" type="search" placeholder="Search"></label>
            </form>
         
    </div>
</div>
    
    <div class="nexmoe-widget-wrap">
    <div class="nexmoe-widget nexmoe-social">
        <a class="mdui-ripple" href="https://space.bilibili.com/213745236" target="_blank" mdui-tooltip="{content: '哔哩哔哩'}" style="color: rgb(231, 106, 141);background-color: rgba(231, 106, 141, .15);">
            <i class="nexmoefont icon-bilibili"></i>
        </a><a class="mdui-ripple" href="https://gitee.com/lxyouneijiang" target="_blank" mdui-tooltip="{content: 'Gitee'}" style="color: rgb(25, 23, 23);background-color: rgba(25, 23, 23, .15);">
            <i class="nexmoefont icon-github"></i>
        </a>
    </div>
</div>
    
    

    
    
    
</aside>
    <div class="nexmoe-copyright">
        &copy; 2022 John Doe
        Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
        & <a href="https://github.com/theme-nexmoe/hexo-theme-nexmoe" target="_blank">Nexmoe</a>
        
    </div>
</div><!-- .nexmoe-drawer -->
    </div>
    <div id="nexmoe-content">
        <div class="nexmoe-primary">
            <div class="nexmoe-post">

  <article>
      
          <div class="nexmoe-post-cover" style="padding-bottom: 66.66666666666666%;"> 
              <img data-src="https://cdn.jsdelivr.net/gh/nexmoe/nexmoe.github.io@latest/images/cover/5c3aec85a4343.jpg" data-sizes="auto" alt="docker常用" class="lazyload">
              <h1>docker常用</h1>
          </div>
      
      
      <div class="nexmoe-post-meta nexmoe-rainbow" style="margin:10px 0!important;">
    <a><i class="nexmoefont icon-calendar-fill"></i>2022年07月14日</a>
</div>

      

      <h2 id="docker"><a href="#docker" class="headerlink" title="docker"></a>docker</h2><h3 id="常用的几个"><a href="#常用的几个" class="headerlink" title="常用的几个"></a>常用的几个</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">docker pull  [name]   拉取镜像</span><br><span class="line">docker search  [name]  查询</span><br><span class="line">docker image 查询所有镜像</span><br><span class="line">docker ps  查询正在运行的镜像</span><br><span class="line">docker ps -a  查询所有镜像 包括 停止的</span><br><span class="line">docker rmi -f 强制删除image</span><br><span class="line">docker <span class="built_in">rm</span> -f 强制删除运行的镜像</span><br><span class="line"></span><br><span class="line">docker <span class="built_in">exec</span> -it  [<span class="built_in">id</span>] /bin/bash   //进去容器内 </span><br><span class="line">docker restart [镜像<span class="built_in">id</span>或者名字]   //重启容器</span><br></pre></td></tr></table></figure>

<h2 id="举列："><a href="#举列：" class="headerlink" title="举列："></a>举列：</h2><h4 id="mysql"><a href="#mysql" class="headerlink" title="mysql:"></a>mysql:</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">1.拉取</span><br><span class="line">docker pull mysql:5.7</span><br><span class="line"></span><br><span class="line">2.启动</span><br><span class="line">docker run -d -p 3306:3306 --privileged=<span class="literal">true</span> </span><br><span class="line">-v /lxy/mysql/log:/var/log/mysql</span><br><span class="line">-v /lxy/mysql/data:/var/lib/mysql</span><br><span class="line">-v /lxy/mysql/conf:/etc/mysql/conf.d</span><br><span class="line">-e MYSQL_ROOT_PASSWORD=123456</span><br><span class="line">--name mysql</span><br><span class="line">mysql:5.7</span><br><span class="line"></span><br><span class="line">3.设置配置文件 进入/lxy/mysql/conf 目录</span><br><span class="line"><span class="built_in">cd</span> /lxy/mysql/conf</span><br><span class="line"></span><br><span class="line">4.创建my.cnf ,然后编写</span><br><span class="line">[client]</span><br><span class="line">default-character-set=utf8</span><br><span class="line">[mysqld]</span><br><span class="line">collation_server=utf8_general_ci</span><br><span class="line">character-set-server=utf8</span><br><span class="line"></span><br><span class="line">5.	重启mysql容器</span><br><span class="line">docker restart mysql</span><br><span class="line"></span><br><span class="line">6.进入容器</span><br><span class="line">docker <span class="built_in">exec</span> -it  mysql  /bin/bash</span><br><span class="line">7.正常食用</span><br><span class="line">mysql -uroot -p</span><br><span class="line">输入密码</span><br><span class="line">然后操作</span><br></pre></td></tr></table></figure>

<h4 id="redis"><a href="#redis" class="headerlink" title="redis"></a>redis</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">1.拉取</span><br><span class="line">docker pull redis:6.0.8</span><br><span class="line">2.修改conf文件 放到指定目录 (lxy/redis/redis.conf)</span><br><span class="line">3.运行redis</span><br><span class="line">docker run -d -p 6379:6379 --name myr3 --privileged=<span class="literal">true</span> -v /lxy/redis/redis.conf:/etc/redis/redis.conf -v /lxy/redis/data:/data -d redis:6.0.8 redis-server /etc/redis/redis.conf </span><br><span class="line">4.docker <span class="built_in">exec</span> -it  myr3 /bin/bash</span><br><span class="line">5.redis-cli</span><br><span class="line">6.正常食用</span><br></pre></td></tr></table></figure>

<h4 id="tomcat"><a href="#tomcat" class="headerlink" title="tomcat"></a>tomcat</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -it -d -p 8080:8080 -v /lxy/tomcat/logs:/usr/local/tomcat/logs -v /lxy/tomcat/webapps:/usr/local/tomcat/webapps/ROOT --name tomcat tomcat</span><br></pre></td></tr></table></figure>
  </article>

  
      
    <div class="nexmoe-post-copyright">
        <strong>Author：</strong>John Doe<br>
        <strong>Link：</strong><a href="https://liuxinyan.gitee.io/2022/07/14/docker%E5%B8%B8%E7%94%A8/" title="https:&#x2F;&#x2F;liuxinyan.gitee.io&#x2F;2022&#x2F;07&#x2F;14&#x2F;docker%E5%B8%B8%E7%94%A8&#x2F;" target="_blank" rel="noopener">https:&#x2F;&#x2F;liuxinyan.gitee.io&#x2F;2022&#x2F;07&#x2F;14&#x2F;docker%E5%B8%B8%E7%94%A8&#x2F;</a><br>
        
            <strong>版权声明：</strong>本文采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/cn/deed.zh" target="_blank">CC BY-NC-SA 3.0 CN</a> 协议进行许可
        
    </div>


  
  
  <div class="nexmoe-post-meta nexmoe-rainbow">
    
    
</div>

  
      <div class="nexmoe-post-footer">
          <section class="nexmoe-comment">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@latest/dist/gitalk.min.css">
<div id="gitalk"></div>
<script src="https://cdn.jsdelivr.net/npm/gitalk@latest/dist/gitalk.min.js"></script>
<script type="text/javascript">
    var gitalk = new Gitalk({
        clientID: '80b2453b6d5f37ad6225',
        clientSecret: '43e99fa852795c9a7b3eb924b2558c64b84bbdeb',
        id: window.location.pathname,
        repo: 'nexmoe.github.io',
        owner: 'nexmoe',
        admin: 'nexmoe'
    })
    gitalk.render('gitalk')
</script>
</section>
      </div>
  
</div>
            <div class="nexmoe-post-right">
              <div class="nexmoe-fixed">
                  <div class="nexmoe-tool"> 
                    
                      
                    
                      <a href="#nexmoe-content" class="toc-link" aria-label="回到顶部" title="top"><button class="mdui-fab mdui-ripple"><i class="nexmoefont icon-caret-top"></i></button></a>
                  </div>
              </div>
            </div>
        </div>
    </div>
     
    <div id="nexmoe-search-space">
        <div class="search-container">
            <div class="search-header">
                <div class="search-input-container">
                    <input class="search-input" type="text" placeholder="Search" oninput="sinput();">
                </div>
                <a class="search-close" onclick="sclose();">×</a>
            </div>
            <div class="search-body"></div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/combine/npm/lazysizes@5.1.0/lazysizes.min.js,npm/mdui@0.4.3/dist/js/mdui.min.js?v=1"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js"></script>

 

<script async src="/js/app.js?v=1657770155242"></script>



<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.8.1/dist/js/jquery.justifiedGallery.min.js"></script>
<script>
	$(".justified-gallery").justifiedGallery({
		rowHeight: 160,
		margins: 10,
	});
</script>


    





</body>

</html>
